var app = getApp();
Page({
    data:{
        apis:app.data.ipconfig,
        id:1,
        data1:false,
        data2:false,
        data3:false,
        data4:false,
        data5:false,
        tixingfahuo:"提醒发货",
        querenshouhuo:"确认收货"
    },
    onLoad:function(param){
        var that=this;
        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersState:1
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.res==0){
                    that.setData({
                        goodslist:res.data.res,
                        data1:false
                    });
                }else{
                    that.setData({
                        goodslist:res.data.res,
                        data1:true
                    });
                }

            }
        })

        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersState:2
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.res==0){
                    that.setData({
                        goodslist2:res.data.res,
                        data2:false
                    });
                }else{
                    that.setData({
                        goodslist2:res.data.res,
                        data2:true
                    });
                }
            }
        })


        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersState:3
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.res==0){
                    that.setData({
                        goodslist3:res.data.res,
                        data3:false
                    });
                }else{
                    that.setData({
                        goodslist3:res.data.res,
                        data3:true
                    });
                }
            }
        })


        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersState:4
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.res==0){
                    that.setData({
                        goodslist4:res.data.res,
                        data4:false
                    });
                }else{
                    that.setData({
                        goodslist4:res.data.res,
                        data4:true
                    });
                }
            }
        })

        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersState:5
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.res==0){
                    that.setData({
                        goodslist5:res.data.res,
                        data5:false
                    });
                }else{
                    that.setData({
                        goodslist5:res.data.res,
                        data5:true
                    });
                }
            }
        })

        that.setData({
            id:param.id
        });
    },
    changeGGColor: function (e) {
        var id= e.target.id;
        var that=this;
        that.setData({
            id:id
        });
        /*that.onLoad();*/
    },
    goPay:function(e){
        var that=this;
        var id= e.currentTarget.id;
        wx.navigateTo({
            url:'../../pages/orderEnd/index?goodOrdersNo='+id
        });
    },
    closeOrder:function(e){
        var that=this;
        var id= e.currentTarget.id;
        console.log(id);
        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/deleteOrders',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersNo:id
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if(res.data.status==200){
                    wx.showToast({
                        title: '订单已取消',
                        icon: 'success',
                        duration: 2000
                    })
                }else{
                    wx.showToast({
                        title: '取消失败，请稍后重试！',
                        icon: 'success',
                        duration: 2000
                    })
                }

                wx.request({
                    url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
                    data: {
                        appid: app.data.appid,
                        openid: wx.getStorageSync('openid'),
                        goodOrdersState:1
                    },
                    header: {
                        'content-type': 'application/json'
                    },
                    success: function (res) {
                        that.setData({
                            goodslist:res.data.res
                        });
                    }
                })
            }
        })
    },
    tixingfahuo:function(){
        var that=this;
        wx.showToast({
            title: '已提醒，请耐心等待！',
            icon: 'success',
            duration: 2000
        })
    },
    querenshouhuo:function(e){
        var that=this;
        var goodOrdersNo= e.currentTarget.dataset.orderid;
        wx.request({
            url: that.data.apis + '/wxxiaochengxu/ordersApi/receiveGood',
            data: {
                appid: app.data.appid,
                openid: wx.getStorageSync('openid'),
                goodOrdersNo:goodOrdersNo
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                wx.request({
                    url: that.data.apis + '/wxxiaochengxu/ordersApi/getOrders',
                    data: {
                        appid: app.data.appid,
                        openid: wx.getStorageSync('openid'),
                        goodOrdersState:3
                    },
                    header: {
                        'content-type': 'application/json'
                    },
                    success: function (res) {
                        if(res.data.res==0){
                            that.setData({
                                goodslist3:res.data.res,
                                data3:false
                            });
                        }else{
                            that.setData({
                                goodslist3:res.data.res,
                                data3:true
                            });
                        }
                        that.onLoad();
                    }
                })
            }
        })

        wx.showToast({
            title: '收货成功！',
            icon: 'success',
            duration: 2000
        })
        that.setData({
            querenshouhuo:'已收货'
        });
    },
    lijipingjia:function(e){
        var that=this;
        var id= e.currentTarget.id;
        wx.navigateTo({
            url:'../../pages/addevaluate/index?goodOrdersNo='+id
        });
    },
    onPullDownRefresh: function() {
        console.log('刷新');
        var that=this;
        setTimeout(function(){
            wx.stopPullDownRefresh();
            that.onLoad();
        },2000)
    }
});